/**
 * 为物理对象自动生成边界
 */
cc.Class({
    extends: cc.Component,

    properties: {
        rigid:{
            default:null,
            type:cc.RigidBody,
        },
        size: cc.size(0, 0),
        thickness: 20,
    },

    // use this for initialization
    onLoad: function () {
        let width   = this.size.width || this.node.width;
        let height  = this.size.height || this.node.height;

        this.rigid = this.rigid || this.getComponent(cc.RigidBody);

        let body = this.rigid;
        let node = body.node;
        
        this._addBound(node, 0, height/2, width, this.thickness);
        this._addBound(node, 0, -height/2, width, this.thickness);
        this._addBound(node, -width/2, 0, this.thickness, height);
        this._addBound(node, width/2, 0, this.thickness, height);
    },

    _addBound (node, x, y, width, height) {
        let collider = node.addComponent(cc.PhysicsBoxCollider);
        collider.offset.x = x;
        collider.offset.y = y;
        collider.size.width = width;
        collider.size.height = height;
    }
});